package logic

import (
	"context"
	"fmt"
	"shopexam/model/mysql"
	"shopexam/model/redis"
	"shopexam/shoprpc/internal/svc"
	"shopexam/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopLikeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopLikeLogic {
	return &ShopLikeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopLikeLogic) ShopLike(in *shoprpc.ShopLikeRequest) (*shoprpc.ShopLikeResponse, error) {
	// todo: add your logic here and delete this line
	var shop mysql.Products
	err := mysql.DB.Debug().Where("id=?", in.Id).Error
	if err != nil {
		return nil, fmt.Errorf("该商品不存在")
	}
	//shop.Like = shop.Like + 1
	//mysql.DB.Debug().Updates(&shop)
	redis.Rdb.ZIncrBy("shop-list", 1, shop.Name)
	return &shoprpc.ShopLikeResponse{}, nil
}
